package com.cat.math;

import java.util.HashMap;
import java.util.HashSet;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/distinct-prime-factors-of-product-of-array/
 * @create 2025/10/16 18:33
 * @since JDK17
 */

public class Solution12 {
    public int distinctPrimeFactors(int[] nums) {
        HashSet<Integer> set = new HashSet<>();
        for (int num : nums) {
            for (int i = 2; i * i <= num; i++) {
                if (num % i == 0) {
                    set.add(i);
                }
                while (num % i == 0) {
                    num /= i;
                }
            }
            if (num > 1) {
                set.add(num);
            }
        }

        return set.size();
    }
}
